// 如果没有通过拦截器配置域名的话，可以在这里写上完整的URL(加上域名部分)
import config from "./config";

// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const install = (Vue, vm) => {
	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {
		getBaseUrl: () => config.baseUrl,
		getWebBaseUrl: () => config.webBaseUrl,
		getUserInfo: (params = {}) => vm.$u.get('/getInfo', params),
		login: (params = {}) => vm.$u.post('/mobile/account/login', params),
		loginOauth: (params = {}) => vm.$u.get('/login-oauth', params),
		watchLogin: (params = {}) => vm.$u.post('/mobile/wx/login', params),
		getOpenid: (params = {}) => vm.$u.post('/mobile/wx/openid', params),
		getSystemConfig: (params = {}) => vm.$u.get('/uniapp/config/system', params),
		updateAccount: (data) => vm.$u.post('/user/auth/updateAccount', data),
		getByKey: (params = {}) => vm.$u.get("/uniapp/config/getByKey", params),
		listMyFillFormRequest: (params = {}) => vm.$u.get("/user/form/data/my", params),
		listTodo: (params = {}) => vm.$u.get('/user/form/todo/page', params),
		bindWechat: (params = {}) => vm.$u.post('/mobile/account/bindWx', params),
		unbindWx: (params = {}) => vm.$u.post('/mobile/account/cancelBindWx'),
		register: (params = {}) => vm.$u.post('/register', params),
		nowRegister: (params = {}) => vm.$u.get('/system/config/sys.account.register/configValue'),
		updateProfile: (params = {}) => vm.$u.put('/system/user/profile', params),
		updatePassword: (params = {}) => vm.$u.post(`/system/user/profile/updatePwd`, params),
		getAnnouncePage: (params = {}) => vm.$u.get('/sys/announce/page', params),
		getWorkflowCounts: (params = {}) => vm.$u.get('/dashboard/workflowCounts', params),
		getFormPage: (params = {}) => vm.$u.get('/user/form/page', params),
		getFormCooperationPage: (params = {}) => vm.$u.get('/user/form/my/cooperation', params),
		getMyAnnouncementSendPage: (params = {}) => vm.$u.get('/sys/announce/getMyAnnouncementSend', params),
		getConfirmationCodeRequest: (params = {}) => vm.$u.post('/form/confirmationCode/use', params),
		readMyAnnouncement: (id) => vm.$u.put(`/sys/announce/read/${id}`),
		getPortal: () => vm.$u.get('/uniapp/portal/getPortal'),
		form: {
			createFormItem: (data = {}) => vm.$u.post('/user/form/item/create', data),
			updateFormItem: (data = {}) => vm.$u.post('/user/form/item/update', data),
			deleteFormItem: (data = {}) => vm.$u.post('/user/form/item/delete', data),
			getFormInfo: (key) => vm.$u.get(`/user/form/${key}`),
			getFormItemList: (params = {}) => vm.$u.get(`/user/form/item/list`, params),
			sortProjectItem: (data = {}) => vm.$u.post('/user/form/item/sort', data),
			createForm: (data = {}) => vm.$u.post('/user/form/create', data),
			updateForm: (params = {}) => vm.$u.post('/user/form/update', params),
			deleteForm: (data = {}) => vm.$u.post('/user/form/delete', data),
			stopForm: (data = {}) => vm.$u.post('/user/form/stop', data),
			// 发布表单
			publishForm: (data = {}) => vm.$u.post('/user/form/publish', data),
			// 逻辑删除表单
			logicDeleteForm: (data = {}) => vm.$u.post('/user/form/logic/delete', data),
			getFormShareQrcode: (formKey) => vm.$u.get('/mobile/form/share-qrcode', {
				formKey
			})
		},
		workflow: {
			getTodoList: (params = {}) => vm.$u.get('/process/task/todoList', params),
			getMyProcess: (params = {}) => vm.$u.get('/process/task/myProcess', params),
			getFinishedList: (params = {}) => vm.$u.get('/process/task/finishedList', params),
			getBusinessProcessForm: (params = {}) => vm.$u.get('/workflow/business/process/form/', params),
			getProcessTaskFlowRecord: (params = {}) => vm.$u.get('/process/task/flow/record', params),
			// 取消申请
			cancelProcess: (data = {}) => vm.$u.post(`/process/task/cancel`, data),
			//我发起的流程
			todoList: (params = {}) => vm.$u.get('/process/task/todoList', params),
			// 完成任务
			complete: (data = {}) => vm.$u.post(`/process/task/complete`, data),
			//完成任务
			rejectTask: (data = {}) => vm.$u.post(`/process/task/reject`, data),
			//完成任务
			returnList: (data = {}) => vm.$u.post(`/process/task/returnList`, data),
			//回退任务到指定节点
			returnTask: (data = {}) => vm.$u.post(`/process/task/return`, data),
			//回退任务到指定节点
			flowRecord: (params = {}) => vm.$u.get(`/process/task/flow/record`, params),
			// 查询允许发起的流程
			allowedInitiatorList: (params = {}) => vm.$u.get(`/flow/allowedInitiatorList`, params),
		}
	};
}

export default {
	install
}
